package com.example.agricultural_big_data.controller;

import com.example.agricultural_big_data.pojo.Adverse;
import com.example.agricultural_big_data.service.AdverseService;
import com.example.agricultural_big_data.util.AjaxResult;
import com.example.agricultural_big_data.util.LoginRequired;
import com.example.agricultural_big_data.util.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName:AdverseController
 * Package:com.example.agricultural_big_data.controller
 * Description:
 *
 * @Data:2022/5/17 1:05
 */
@RestController
@CrossOrigin
@RequestMapping("/adverse")
public class AdverseController extends BaseController {

    @Autowired
    private AdverseService adverseService;

    @LoginRequired
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Adverse adverse){
        return toAjax(adverseService.addAdverse(adverse));
    }

    @GetMapping("/list")
    public TableDataInfo list(String userId){
        List<Adverse> adverses = adverseService.getListByUserId(userId);
        return getDataTable(adverses);
    }
}
